﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Windows.Browser.Net;
using System.Windows.Documents;
using System.Windows.Media;
using System.Xml;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using System.Windows.Shapes;



namespace AgLux
{
    public class Link : Component
    {
        protected TextBlock _text;
        protected Run _link;        
        protected string _url;
        protected bool _clicked;
        public Link(string url, string text)
            : base()
        {
            
            _text = (TextBlock)_resource.FindName("text");
            _text.MouseEnter += new MouseEventHandler(_text_MouseEnter);
            _text.MouseLeave += new EventHandler(_text_MouseLeave);
            _text.MouseLeftButtonUp += new MouseEventHandler(_text_MouseLeftButtonUp);
            _link = new Run();
            _link.Text = text;
            _text.Inlines.Add(_link);
            _url = url;
            _text.Visibility = Visibility.Visible;
            TextDecorations decoration = new TextDecorations();
            decoration = TextDecorations.Underline;
            _link.TextDecorations = decoration;



        }

        void _text_MouseLeftButtonUp(object sender, MouseEventArgs e)
        {
            _clicked = true;
            _link.Foreground = new SolidColorBrush(Colors.Blue);
            //System.Windows.Browser.HtmlPage.Navigate(_url, "myTarget");
            System.Windows.Browser.HtmlPage.Navigate(_url, "myTarget");
           
        }

        void _text_MouseLeave(object sender, EventArgs e)
        {
            if (_clicked)
            {
                _link.Foreground = new SolidColorBrush(Colors.Blue);
            }
            else
            {
                _link.Foreground = new SolidColorBrush(Colors.Black);
            }
        }

        void _text_MouseEnter(object sender, MouseEventArgs e)
        {
            _link.Foreground =  new SolidColorBrush(Colors.Purple);
        }

        



        public override void FitCanvas(double canvasWidth)
        {
            Width = ScreenWidth = canvasWidth;
            Height = ScreenHeight = _text.ActualHeight;
        }

        /// <summary>
        /// //
        /// </summary>

        /// <param name="value">
        /// //
        /// </param>

        protected override double ScreenWidth
        {
            set
            {
                _screen.Width = _text.Width = value;
            }
        }
        /// <summary>
        /// //
        /// </summary>

        /// <param name="value">
        /// //
        /// </param>

        protected override double ScreenHeight
        {
            set
            {
                _screen.Height = _text.Height = value;
            }
        }
    }
}
